<%--
  Created by IntelliJ IDEA.
  User: 山志凯
  Date: 2021-04-23
  Time: 14:30
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java"  errorPage="500.jsp" %>
<html>
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width,initial-scale=1.0"/>
    <title>jsp页面的9大内置对象</title>
</head>
<body>

<%--模拟异常  转到500.jsp--%>
<%--<%--%>
<%--    try {--%>
<%--        int a=1/0;--%>
<%--    }catch (Exception e) {--%>
<%--        throw new Exception("除数不能为0！");--%>
<%--    }--%>
<%--%>--%>

<%--pageContext对象--%>
<%--1、域对象，可以存放key-value信息，有效范围是当前页面--%>
<%
    //pageContext.setAttribute("msg","pageContext");
    //pageContext.setAttribute("msg","pageContext",1);
    //pageContext.setAttribute("msg","pageContext",PageContext.PAGE_SCOPE);
    pageContext.setAttribute("msg","request",PageContext.REQUEST_SCOPE);
    pageContext.setAttribute("msg","session",PageContext.SESSION_SCOPE);
    pageContext.setAttribute("msg","application",PageContext.APPLICATION_SCOPE);
%>
<br>
<%--获取所有域对象key-value:msg:object--%>
pageContext.mag=<%=pageContext.getAttribute("mag")%>
pageContext.mag=<%=pageContext.getAttribute("msg",PageContext.PAGE_SCOPE)%>
request.mag=<%=pageContext.getAttribute("msg",PageContext.REQUEST_SCOPE)%>
session.mag=<%=pageContext.getAttribute("msg",PageContext.SESSION_SCOPE)%>
application.mag=<%=pageContext.getAttribute("msg",PageContext.APPLICATION_SCOPE)%>
<br>
<%--<%=request.getAttribute("msg")%>--%>
<%--<%=session.getAttribute("msg")%>--%>
<%--<%=application.getAttribute("msg")%>--%>

<%--它会--%>
msg=<%=pageContext.findAttribute("msg")%>

<%--2、pageContext对象可以获取其他8个内置对象--%>
<%
    Object page1 = pageContext.getPage();
    ServletRequest request1 = pageContext.getRequest();
    ServletResponse response1 = pageContext.getResponse();
    HttpSession session1 = pageContext.getSession();
    ServletConfig servletConfig = pageContext.getServletConfig();
    ServletContext servletContext = pageContext.getServletContext();
    JspWriter out1 = pageContext.getOut();
    Exception exception = pageContext.getException();

<%--    page1=<%=page1%><br>--%>

%>
</body>
</html>
